import SwiftUI

// RegisterPage
// 注册界面

struct RegisterPage: View {
    @Environment(\.modelContext) private var modelContext
    
    @State private var showLogo: Bool = true
    
    @Binding var phoneNumberInput: String
    @Binding var passwordInput: String
    
    @Binding var registerStatus: Bool
    
    var body: some View {
        ZStack(alignment: .center) {
            // 背景图片
            Image("Background")
                .resizable()
                .ignoresSafeArea()
            
            VStack {
                if showLogo {
                    Spacer()
                    Image("Logo")
                        .resizable()
                        .scaledToFit()
                        .frame(width: 140, height: 140)
                        .padding(.bottom, 20)
                }
                
                Text("注册")
                    .font(.largeTitle)
                    .foregroundColor(.white)
                    .padding(.bottom, 20)
                
                RegisterWindow(phoneNumberInput: $phoneNumberInput,
                               passwordInput: $passwordInput,
                               registerStatus: $registerStatus)
                    .modelContext(modelContext)
                
                Spacer()
            }
        }
        .onReceive(keyboardPublisher) { isKeyboard in
            showLogo = !isKeyboard
        }
    }
}

#Preview {
    @State var phoneNumberInput: String = ""
    @State var passwordInput: String = ""
    
    return RegisterPage(phoneNumberInput: $phoneNumberInput,
                        passwordInput: $passwordInput,
                        registerStatus: .constant(false))
}
